#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;
const int N = 26;
int n;
int ret;
bool st1[2 * N];
bool col[N];
bool st2[2 * N];
vector<int> path;
void dfs(int pos)
{
    if (pos > n)
    {
        ret++;
        if (ret <= 3)
        {
            for (auto e : path)
            {
                cout << e << ' ';
            }
            cout << endl;
        }
        return;
    }
    for (int y = 1; y <= n; y++)
    {
        if (col[y])
        {
            continue;
        }
        if (st1[y - pos + n])
        {
            continue;
        }
        if (st2[y + pos])
        {
            continue;
        }
        path.push_back(y);
        col[y] = true;
        st1[y - pos + n] = true;
        st2[y + pos] = true;
        dfs(pos + 1);
        col[y] = false;
        st1[y - pos + n] = false;
        st2[y + pos] = false;
        path.pop_back();
    }

}

int main()
{
    cin >> n;
    dfs(1);
    cout << ret;
    return 0;
}